package com.koicarp.university.graduate.web.controller;

import com.koicarp.university.graduate.auth.annotation.OperLog;
import com.koicarp.university.graduate.auth.constant.ModuleNameEnum;
import com.koicarp.university.graduate.auth.constant.OperateLogTypeEnum;
import com.koicarp.university.graduate.service.entity.report.ReportType;
import com.koicarp.university.graduate.service.service.report.IReportTypeService;
import com.koicarp.university.graduate.service.vo.mission.ReportTypeVo;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther liutao
 * @Date 2020-12-03 14:32:53
 */
@Slf4j
@RestController
@RequestMapping("reportType")
@RequiredArgsConstructor
@Api(tags = "(报表类型表)表控制层")
public class ReportTypeController {
    private final IReportTypeService reportTypeService;

    @PostMapping("getReportTypeWithPage")
    @ApiOperation(value = "报表类型-普通查询，分页",notes = "报表类型-普通查询，分页")
    public UniversityResponse getReportTypeWithPage(@RequestBody ReportTypeVo vo){
        UniversityResponse response=null;
        try{
            if (vo.getSort().equals("+id")){
                vo.setSort("asc");
            }else{
                vo.setSort("desc");
            }
            response = reportTypeService.getReportTypeWithPage(vo);
        }catch (Exception e){
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("modifyReportType")
    @ApiOperation(value = "修改报表状态" ,notes = "修改报表状态")
    @OperLog(moduleName = ModuleNameEnum.GraManage,type = OperateLogTypeEnum.UPDATE,operDesc = "修改小程序问卷启用与禁止")
    public UniversityResponse modifyReportType(@RequestBody ReportType reportType){
        UniversityResponse response=null;
        try{
            response = reportTypeService.update(reportType);
        }catch (Exception e){

            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

}
